package com.jeesite.modules.dp.service.patternstatics;

import com.jeesite.common.lang.DateUtils;
import com.jeesite.modules.dp.dao.patrernstatics.MarketStockSignalDao;
import com.jeesite.modules.dp.dto.vo.MarkStockSignalLineRecord;
import com.jeesite.modules.dp.entity.patrernstatics.MarketStockSignalEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class MarketStockSignalService {

    @Autowired
    private MarketStockSignalDao marketStockSignalDao;

    public Map<String, Object> getStockSignalList(int limit) {
        List<MarketStockSignalEntity> list = marketStockSignalDao.getStockSignalList(limit);
        list.sort(Comparator.comparing(MarketStockSignalEntity::getDate));
        List<MarkStockSignalLineRecord> records = new ArrayList<>();
        int[] ups = new int[list.size()];
        int[] downs = new int[list.size()];
        int index = 0;
        List<String> dates = new ArrayList<>();
        for (MarketStockSignalEntity data : list) {
            ups[index] = (data.getSignalUps());
            downs[index] = (data.getSignalDowns());
            dates.add(DateUtils.formatDate(data.getDate(), "yyyy-MM-dd"));
            index++;
        }
        MarkStockSignalLineRecord upRecord = new MarkStockSignalLineRecord("UP", "line", ups);
        MarkStockSignalLineRecord downRecord = new MarkStockSignalLineRecord("DOWN", "line", downs);

        Map<String, Object> mr = new HashMap<>();
        mr.put("data", Arrays.asList(upRecord, downRecord));
        mr.put("xaxis", dates);
        return mr;
    }
}
